package com.example.dps;

import java.io.File;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;



public class SetupAccountActivity extends Activity{
	
	String tag = "SETUPACCOUNTACTIVITY";

	/** current step of account registration **/
	public int stepNumber = 1;
	
	/** total steps in setup process **/
	public int stepTotal = 5;
	
	
	/** step to create login information **/
	public final static int SETUP_USERNAME_STEP = 1;
	/** step to add basic info such as name and address **/
	public final static int SETUP_BASICINFO_STEP = 2;
	/** step to take picture of ID **/
	public final static int SETUP_ID_STEP = 3;
	/** step to confirm agreements **/
	public final static int SETUP_AGREEMENT_STEP = 4;
	/**step to add checking and routing number **/
	public final static int SETUP_CHECKING_STEP = 5;
	
	
	
	/** layout for username_step **/
	public final static int USERNAME_LAYOUT = R.layout.setup_account_username_layout;
	/** layout for basic info step **/
	public final static int BASICINFO_LAYOUT = R.layout.setup_account_basic_info_layout;
	/**layout for ID step **/
	public final static int ID_LAYOUT = R.layout.setup_account_id_layout;
	/**layout for Checking step **/
	public final static int CHECKING_LAYOUT = R.layout.setup_account_checking_layout;
	
	
	/** code to start camera intent **/
	private static final int CAMERA_REQUEST = 1888; 
	
	public boolean takePictureOfFront = true;
	
	public String[] registerAccountInfo = new String[4];
	
	/** saved information from account form. page one **/
	public String[] basicInfo = new String[9];
	
	public Drawable[] IDInfo = new Drawable[2];
	
	/**saved information from account form. page four **/
	public String[] checkingInfo = new String[2];
	
	public AccountDBHelper accountDBHelper;
	
	public WebHelper webHelper;
	
	
	
	
	@Override
	public void onDestroy(){
		super.onDestroy();
	}
	
	@Override
	 public void onWindowFocusChanged(boolean hasFocus) {
	  super.onWindowFocusChanged(hasFocus);
	  
	 }
	
	
	private Uri imageUri;
	
	@Override
	public void onConfigurationChanged(Configuration newConfig){
		super.onConfigurationChanged(newConfig);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}

	public void takePhoto() {
	    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
	    File photo = new File(Environment.getExternalStorageDirectory(),  "Pic.jpg");
	    intent.putExtra(MediaStore.EXTRA_OUTPUT,
	            Uri.fromFile(photo));
	    imageUri = Uri.fromFile(photo);
	    startActivityForResult(intent, CAMERA_REQUEST);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
	    super.onActivityResult(requestCode, resultCode, data);
	    switch (requestCode) {
	    case CAMERA_REQUEST:
	        if (resultCode == Activity.RESULT_OK) {
	        	
	        	
	            Uri selectedImage = imageUri;
	            getContentResolver().notifyChange(selectedImage, null);
	            
	            ImageView imageView;
	            
	            if(this.takePictureOfFront){
	            	imageView = (ImageView) findViewById(R.id.setupAccountFrontLicensePicture);
	            }
	            else{
	            	imageView = (ImageView) findViewById(R.id.setupAccountBackLicensePicture);
	            }
	            
	            imageView.setVisibility(View.VISIBLE);
	            
	            ContentResolver cr = getContentResolver();
	            Bitmap bitmap;
	            try {
	                 bitmap = android.provider.MediaStore.Images.Media
	                 .getBitmap(cr, selectedImage);

	                imageView.setImageBitmap(bitmap);
	                Toast.makeText(this, selectedImage.toString(),
	                        Toast.LENGTH_LONG).show();
	            } catch (Exception e) {
	                Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT)
	                        .show();
	                Log.e("Camera", e.toString());
	            }
	        }
	    }
	}
    
    
	@Override
	public Dialog onCreateDialog(int id) {
		
		Log.e("asdfadf", "called on create Dialog");
		
	    AlertDialog.Builder builder = new AlertDialog.Builder(this);
	    builder.setTitle("Select State:")
	           .setItems(R.array.states_array, new DialogInterface.OnClickListener() {
	               public void onClick(DialogInterface dialog, int which) {
	            	   String[] states = SetupAccountActivity.this.getResources().getStringArray(R.array.states_array);
	            	   
	            	   String state = states[which];

	            	   TextView stateText = (TextView) findViewById(R.id.setupAccountHomeStateValue);
	            	   stateText.setText(state);

	            	   
	            	   ScrollView sv = (ScrollView) findViewById(R.id.setupAccountScrollView);
	            	   sv.fullScroll(ScrollView.FOCUS_DOWN);
	               }
	    });
	    return builder.create();
	}
	
	public void onResume(){
		super.onResume();
		
		this.accountDBHelper = new AccountDBHelper(this);
		
		this.webHelper = new WebHelper(this);
		
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setup_account_layout);
		
		Drawable background = Utility.returnAdjustedBackgroundDrawable(this);
		
		LinearLayout root = (LinearLayout) findViewById(R.id.root);
		
		root.setBackgroundDrawable(background);
		
		
		this.accountDBHelper = new AccountDBHelper(this);
		
		this.webHelper = new WebHelper(this);
		
		updateProgressBar();
		
		/** add the step layout **/
		LinearLayout mainContentLayout = (LinearLayout)findViewById(R.id.setupAccountMainContent);
		
		LayoutInflater inflater = SetupAccountActivity.this.getLayoutInflater();
		
		mainContentLayout.addView(inflater.inflate(R.layout.setup_account_username_layout, mainContentLayout, false));
		
		
		addButtonListeners();
		
		Handler handler=new Handler();
		Runnable r=new Runnable()
		{
		    public void run() 
		    {
		    	ScrollView sv = (ScrollView) findViewById(R.id.setupAccountScrollView);
         	   	sv.fullScroll(ScrollView.FOCUS_UP); 			
		    }
		};
		handler.postDelayed(r, 100);
		
		
		restoreFormInfo();
		

	}
	
	
	public void addButtonListeners(){
		
		ImageView backButton = (ImageView) findViewById(R.id.setupAccountBackButton);
		
		backButton.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				
				int step = SetupAccountActivity.this.stepNumber;
				
				if(step > 1){
					SetupAccountActivity.this.stepNumber--;
					SetupAccountActivity.this.changeToStepLayout();
				}
				else{
					SetupAccountActivity.this.finish();
				}
				
			}
			
		});
		
		
		/** all forms have a continue button, except the Legal form (it has accept/decline) **/
		if(stepNumber != SETUP_AGREEMENT_STEP){
			
			ImageView continueButton = (ImageView) findViewById(R.id.setupContinueBtn);
			
			continueButton.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					
					/** save information **/
					SetupAccountActivity.this.saveFormInfo();
					
					if(checkFormInfoComplete()){
						/** go to next step**/
						SetupAccountActivity.this.stepNumber+=1;
						
						
						if(SetupAccountActivity.this.stepNumber >= SetupAccountActivity.this.stepTotal){

							Log.e("DONE", "SETUP DONE, GOING TO ADD MONEY LAYOUT");
							/** add account to DB **/
							SetupAccountActivity.this.addAccount();
							Log.e("added", "ADDED ACCOUNT SETUPACTIVITY");
							if(!SetupAccountActivity.this.accountDBHelper.hasDPSAccount()) SetupAccountActivity.this.addDPSAccount();
							
							/** form complete, go to add money **/
							Intent intent = new Intent(SetupAccountActivity.this, TabRoot.class);
							intent.putExtra("accountCreated", true);
							intent.putExtra("START_TAB", "add_money");
							Log.e("ASDF", "STARTING ACTIVITY IN SETUPACOUT ACTIVTY");
							SetupAccountActivity.this.startActivity(intent);
						}
						
						
						/** change layout accordingly **/
						else {
							Log.e("asdf", "GOING TO STEP LAYOUT = + " + SetupAccountActivity.this.stepNumber);
							SetupAccountActivity.this.changeToStepLayout();
						}
					}
					
					else{
						/**TODO TOAST**/
					}
					
					
				}
			});
			
			continueButton.setOnTouchListener(new OnTouchListener(){

				@Override
				public boolean onTouch(View v, MotionEvent event) {
					
					ImageView view = (ImageView) v;
					
					if(event.getAction() == MotionEvent.ACTION_DOWN){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.continue_btn_clicked));
					}
					else if(event.getAction() == MotionEvent.ACTION_UP){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.continue_btn));
					}
					else if(event.getAction() == MotionEvent.ACTION_CANCEL){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.continue_btn));
					}
					
					
					
					return false;
				}
				
			});
			
		}
		
		
		if(stepNumber == SETUP_BASICINFO_STEP){
			/** step 1 button listeners **/
			EditText stateLayout = (EditText) findViewById(R.id.setupAccountHomeStateValue);
			
			stateLayout.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View arg0) {
					Log.e("setup dialog", "CLICKED STATE BUTTON");
					showDialog(1);
					
				}
				
			});
		}
		
		else if (stepNumber == SETUP_ID_STEP){
			
			ImageView frontPictureButton = (ImageView) findViewById(R.id.setupAccountFrontLicenseIcon);
			
			frontPictureButton.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					SetupAccountActivity.this.takePictureOfFront = true;
					takePhoto();
					
				}
				
			});
			
			frontPictureButton.setOnTouchListener(new OnTouchListener(){

				@Override
				public boolean onTouch(View v, MotionEvent event) {

					
					
					ImageView view = (ImageView) v;
					
					if(event.getAction() == MotionEvent.ACTION_DOWN){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.camera_icon_clicked));
					}
					else if (event.getAction() == MotionEvent.ACTION_UP){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.camera_icon));
					}
					else if(event.getAction() == MotionEvent.ACTION_CANCEL){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.camera_icon));
					}
					
					return false;
				}
				 
			 });
			
			
			
			ImageView backPictureButton = (ImageView) findViewById(R.id.setupAccountBackLicenseIcon);
			
			backPictureButton.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					
					
					SetupAccountActivity.this.takePictureOfFront = false;
					takePhoto();
					
				}
				
			});
			
			backPictureButton.setOnTouchListener(new OnTouchListener(){

				@Override
				public boolean onTouch(View v, MotionEvent event) {
					
					
					
					ImageView view = (ImageView) v;
					
					if(event.getAction() == MotionEvent.ACTION_DOWN){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.camera_icon_clicked));
					}
					else if (event.getAction() == MotionEvent.ACTION_UP){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.camera_icon));
					}
					else if(event.getAction() == MotionEvent.ACTION_CANCEL){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.camera_icon));
					}
					
					
					return false;
				}
				 
			 });
			
		}
		else if (stepNumber == SETUP_AGREEMENT_STEP){
			
			ImageButton agreeButton = (ImageButton) findViewById(R.id.acceptButton);
			
			agreeButton.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View view) {
					
					SetupAccountActivity.this.stepNumber++;
					SetupAccountActivity.this.changeToStepLayout();
				}	
			});
			
			agreeButton.setOnTouchListener(new OnTouchListener(){

				@Override
				public boolean onTouch(View v, MotionEvent event) {
					
					
					
					ImageView view = (ImageView) v;
					
					if(event.getAction() == MotionEvent.ACTION_DOWN){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.accept_btn_clicked));
					}
					else if (event.getAction() == MotionEvent.ACTION_UP){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.accept_btn));
					}
					else if(event.getAction() == MotionEvent.ACTION_CANCEL){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.accept_btn));
					}
					
					
					return false;
				}
				 
			 });
			
			
			ImageButton declineButton = (ImageButton) findViewById(R.id.declineButton);
			
			declineButton.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View view) {
					
					SetupAccountActivity.this.stepNumber = 0;
					SetupAccountActivity.this.finish();
				}	
			});
			
			declineButton.setOnTouchListener(new OnTouchListener(){

				@Override
				public boolean onTouch(View v, MotionEvent event) {
					
					
					
					ImageView view = (ImageView) v;
					
					if(event.getAction() == MotionEvent.ACTION_DOWN){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.decline_btn_clicked));
					}
					else if (event.getAction() == MotionEvent.ACTION_UP){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.decline_btn));
					}
					else if(event.getAction() == MotionEvent.ACTION_CANCEL){
						view.setImageDrawable(view.getResources().getDrawable(R.drawable.decline_btn));
					}
					
					
					return false;
				}
				 
			 });
		}
		
	}

	protected void changeToStepLayout() {
		
		LinearLayout mainContentLayout = (LinearLayout)findViewById(R.id.setupAccountMainContent);
		
		LayoutInflater inflater = SetupAccountActivity.this.getLayoutInflater();
		
		mainContentLayout.removeAllViews();
		
		int resource = -1;
		
		TableRow acceptLayout = (TableRow) findViewById(R.id.acceptLayout);
		acceptLayout.setVisibility(View.GONE);
		
		
		if(stepNumber == this.SETUP_USERNAME_STEP){
			
			resource = R.layout.setup_account_username_layout;
			
		}
		
		else if(stepNumber == this.SETUP_BASICINFO_STEP){
			resource = R.layout.setup_account_basic_info_layout;
			
			Handler handler=new Handler();
			Runnable r=new Runnable()
			{
			    public void run() 
			    {
			    	ScrollView sv = (ScrollView) findViewById(R.id.setupAccountScrollView);
			    	sv.scrollTo(0, 0);
			    }
			};
			handler.postDelayed(r, 20);
			
		}
		if(stepNumber == SETUP_ID_STEP) resource = R.layout.setup_account_id_layout;
		if(stepNumber == SETUP_AGREEMENT_STEP){
			resource = R.layout.setup_account_agreement_layout;
			acceptLayout.setVisibility(View.VISIBLE);
		}
		if(stepNumber == SETUP_CHECKING_STEP) resource = R.layout.setup_account_checking_layout;
		
		
		mainContentLayout.addView(inflater.inflate(resource, mainContentLayout, false));
		
		updateProgressBar();
		
		addButtonListeners();
		
		restoreFormInfo();
		
		
		
		
		
	}
	
	public void updateProgressBar(){
		
		TextView stepText = (TextView) findViewById(R.id.stepText);
		stepText.setText("Step " + stepNumber + " of " + stepTotal);
		
		
		ProgressBar progressBar = (ProgressBar) findViewById(R.id.setupAccountProgress);
		progressBar.setMax(this.stepTotal);
		
		progressBar.setProgress(stepNumber);
	}
	
	
	/**
	 *  temporarily saves the form information for each page of the setup form
	 *  destroyed at end of activity
	 */
	public void saveFormInfo(){
		
		if(stepNumber == SETUP_USERNAME_STEP){
			registerAccountInfo[0] = ((EditText) findViewById(R.id.setupAccountUserNameValue)).getText().toString();
			registerAccountInfo[1] = ((EditText) findViewById(R.id.setupAccountEmailValue)).getText().toString();
			
			/** must encrypt passwords **/
			registerAccountInfo[2] = (((EditText) findViewById(R.id.setupAccountPasswordValue)).getText().toString());
			registerAccountInfo[3] = (((EditText) findViewById(R.id.setupAccountConfirmPasswordValue)).getText().toString());
			
		}
		
		if(stepNumber == SETUP_BASICINFO_STEP){
			
			/** enter the form information **/
			basicInfo[0] = ((EditText) findViewById(R.id.setupAccountNameValue)).getText().toString();
			basicInfo[1] = ((EditText) findViewById(R.id.setupAccountBirthDateValue)).getText().toString();
			basicInfo[2] = ((EditText) findViewById(R.id.setupAccountSocialSecurityValue)).getText().toString();
			basicInfo[3] = ((EditText) findViewById(R.id.setupAccountEmployerValue)).getText().toString();
			basicInfo[4] = ((EditText) findViewById(R.id.setupAccountPhoneNumberValue)).getText().toString();
			basicInfo[5] = ((EditText) findViewById(R.id.setupAccountHomeAddressValue)).getText().toString();
			basicInfo[6] = ((EditText) findViewById(R.id.setupAccountHomeCityValue)).getText().toString();
			basicInfo[7] = ((EditText) findViewById(R.id.setupAccountHomeStateValue)).getText().toString();
			basicInfo[8] = ((EditText) findViewById(R.id.setupAccountHomeZipValue)).getText().toString();
			
			for(int i = 0; i < 9; i++){
				Log.e("fields", basicInfo[i]);
			}
			
		}
		
		if(stepNumber == SETUP_ID_STEP){
			IDInfo[0] = ((ImageView) findViewById(R.id.setupAccountFrontLicensePicture)).getDrawable();
			IDInfo[1] = ((ImageView) findViewById(R.id.setupAccountBackLicensePicture)).getDrawable();
			
		}

		
		if(stepNumber == SETUP_CHECKING_STEP){
			checkingInfo[0] = ((EditText)findViewById(R.id.setupAccountRoutingNumber)).getText().toString();
			checkingInfo[1] = ((EditText)findViewById(R.id.setupAccountAccountNumber)).getText().toString();
			
		}

	}
	
	public boolean checkFormInfoComplete(){
		
		/** check if register username form completed **/
		if(stepNumber == SETUP_USERNAME_STEP){
			
			Log.e(tag, "Checking form info for setup username step");
			
			/** check info is complete **/
			for(int i = 0; i < registerAccountInfo.length;i++){
				
				if(registerAccountInfo[i] == null || registerAccountInfo[i].equals("")){
					Toast.makeText(this, "Please complete the form before continuing.", Toast.LENGTH_LONG).show();
					return false;
				}

			}
			
			if(this.webHelper.hasConnection() == false){
				Toast.makeText(this, "No internet connection available", Toast.LENGTH_LONG).show();
				return false;
			}
			
			
			/** check that username is not taken **/
			String username = registerAccountInfo[0];
			if(this.webHelper.checkUsernameAvailable(username) == false){
				Toast.makeText(this, "Username is not available", Toast.LENGTH_LONG).show();
				return false;
			}
			
			/** check that passwords match **/
			String password = registerAccountInfo[2];
			String confirmPassword = registerAccountInfo[3];
			Log.e(tag, "check1");
			if(password != null && confirmPassword != null && !password.equals(confirmPassword)){
				Log.e(tag, "passwords do not match");
				Toast.makeText(this, "Passwords do not match!", Toast.LENGTH_LONG).show();
				
				return false;
			}
			
			
			
			
			
			
			
		}
		
		if(stepNumber == -SETUP_BASICINFO_STEP){
			int fieldTotal = 9;
			
			for(int i = 0; i < fieldTotal; i++){
				if(basicInfo[i].equals("")){
					
					Toast.makeText(this.getBaseContext(),"Please complete the form before continuing", 
			                Toast.LENGTH_LONG).show();
					
					return false;
				}
			}

		}
		if(stepNumber == -SETUP_ID_STEP){
			
			/** check that both pictures are uploaded **/
			ImageView frontPicture = (ImageView) findViewById(R.id.setupAccountFrontLicensePicture);
			ImageView backPicture = (ImageView) findViewById(R.id.setupAccountBackLicensePicture);
			
			if(frontPicture.getDrawable() == null){
				Toast.makeText(this, "Please upload a picture of the front side of your license", Toast.LENGTH_LONG).show();
				return false;
			}
			else if(backPicture.getDrawable() == null){
				Toast.makeText(this, "Please upload a picture of the back side of your license", Toast.LENGTH_LONG).show();
				return false;
			}
			
		}
		
		if(stepNumber == SETUP_AGREEMENT_STEP){
			
			
		}
		
		
		if(stepNumber == -SETUP_CHECKING_STEP){
			for(int i = 0; i < checkingInfo.length; i++){
				
				Log.e("page 4", checkingInfo[i]);
				
				if(checkingInfo[i].equals("")){
					Toast.makeText(this, "Please complete the form before continuing", Toast.LENGTH_LONG).show();
					return false;
				}
			}
			
		}
		
		return true;
		
	}
	
	public void restoreFormInfo(){
		
		Bundle extras = this.getIntent().getExtras();
		
		/** if user wants to edit account, restore page info from intent extras **/
		boolean editAccount = false;
		if(extras != null) editAccount = extras.getBoolean("editAccount");
		
		if(editAccount){
			
			Log.e("EDITACCOUNT", "EDIT ACCOUNT = TRUE");
			Cursor accountCursor = accountDBHelper.getAccountAsCursor(extras.getString("accountName"));
			
			if(accountCursor.moveToFirst()){
				
				Log.e("EDITACCOUNT", "CURSORE MOVED TO FIRST");
				String fullName = accountCursor.getString(accountCursor.getColumnIndex(accountDBHelper.COLUMN_ACCOUNT_FULLNAME));
				String birthDate = accountCursor.getString(accountCursor.getColumnIndex(accountDBHelper.COLUMN_ACCOUNT_BIRTHDATE));
				
				basicInfo[0] = fullName;
				basicInfo[1] = birthDate;
				
			}
			
			
			
		}
		
		switch(stepNumber){
		case SETUP_BASICINFO_STEP:
			/** enter the form information **/
			((EditText) findViewById(R.id.setupAccountNameValue)).setText(basicInfo[0]);
			((EditText) findViewById(R.id.setupAccountBirthDateValue)).setText(basicInfo[1]);
			((EditText) findViewById(R.id.setupAccountSocialSecurityValue)).setText(basicInfo[2]);
			((EditText) findViewById(R.id.setupAccountEmployerValue)).setText(basicInfo[3]);
			((EditText) findViewById(R.id.setupAccountPhoneNumberValue)).setText(basicInfo[4]);
			((EditText) findViewById(R.id.setupAccountHomeAddressValue)).setText(basicInfo[5]);
			((EditText) findViewById(R.id.setupAccountHomeCityValue)).setText(basicInfo[6]);
			((EditText) findViewById(R.id.setupAccountHomeStateValue)).setText(basicInfo[7]);
			((EditText) findViewById(R.id.setupAccountHomeZipValue)).setText(basicInfo[8]);
			
			break;
			
		case SETUP_AGREEMENT_STEP:
			WebView webView = (WebView) findViewById(R.id.viewResourcesWebView);
			webView.getSettings().setJavaScriptEnabled(true);
			webView.loadUrl("file:///android_asset/Legal.html");
		
		}
		
	}
	
	/**
	 * takes all the form info, puts it in Content Values and adds it to the accounts database
	 */
	public void addAccount(){
		
		/** put all the form data into content values **/
		ContentValues values = new ContentValues();
		
		
		/** page one info **/
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_FULLNAME, basicInfo[0]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_BIRTHDATE, basicInfo[1]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_SOCIAL_SECURITY, basicInfo[2]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_EMPLOYER, basicInfo[3]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_PHONE_NUMBER, basicInfo[4]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_HOME_ADDRESS, basicInfo[5]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_HOME_CITY, basicInfo[6]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_HOME_STATE, basicInfo[7]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_HOME_ZIP, basicInfo[8]);
		
		/** page 4 info **/
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_CHECKNUM, checkingInfo[0]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_ROUTENUM, checkingInfo[1]);
		
		/** default account name = "checking account" **/
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_NAME, "Checking Account");
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_AMOUNT, 3000);
		
		
		String username = registerAccountInfo[0];
		String email = registerAccountInfo[1];
		String password = registerAccountInfo[2];
		
		Log.e(tag, "calling webHelper.registerUser");
		this.webHelper.registerUser(username, password, email);
		
		Log.e(tag, "calling webHelper.registerAccount()");
		this.webHelper.registerAccount(values);

		
		
	}
	
	public void addDPSAccount(){
		
		/** put all the form data into content values **/
		ContentValues values = new ContentValues();
		
		
		/** page one info **/
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_FULLNAME, basicInfo[0]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_BIRTHDATE, basicInfo[1]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_SOCIAL_SECURITY, basicInfo[2]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_EMPLOYER, basicInfo[3]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_PHONE_NUMBER, basicInfo[4]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_HOME_ADDRESS, basicInfo[5]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_HOME_CITY, basicInfo[6]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_HOME_STATE, basicInfo[7]);
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_HOME_ZIP, basicInfo[8]);
		
		/** page 4 info **/
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_CHECKNUM, "DPS_accountNo");
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_ROUTENUM, "DPS_routeNo");
		
		/** default account name = "Down Payment Saver **/
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_NAME, "Down Payment Saver");
		values.put(this.accountDBHelper.COLUMN_ACCOUNT_AMOUNT, 0);
		
		//this.accountDBHelper.addAccount(values);
		
		/** add to WEB HELPER to add account online **/
		this.webHelper.registerAccount(values);
		
	}
	
}
